package com.deer.wms.inventory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deer.wms.inventory.dao.InventoryAdjustMapper;
import com.deer.wms.inventory.model.InventoryAdjust;
import com.deer.wms.inventory.model.InventoryAdjustCriteria;
import com.deer.wms.inventory.model.InventoryAdjustDto;
import com.deer.wms.inventory.service.InventoryAdjustDetailService;
import com.deer.wms.inventory.service.InventoryAdjustService;
import com.deer.wms.project.root.service.SuperServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by ll on 2020/02/13.
 */
@Service
@Transactional
public class InventoryAdjustServiceImpl extends SuperServiceImpl<InventoryAdjustMapper, InventoryAdjust> implements InventoryAdjustService {

    @Autowired
    private InventoryAdjustMapper inventoryAdjustMapper;
    @Autowired
    private InventoryAdjustDetailService inventoryAdjustDetailService;

    @Override
    public List<InventoryAdjustDto> findList(InventoryAdjustCriteria inventoryAdjustCriteria){
        return inventoryAdjustMapper.findList(inventoryAdjustCriteria);
    }

    @Override
    public InventoryAdjust findBy(String field, String value) {
        QueryWrapper<InventoryAdjust> qw = new QueryWrapper<>();
        return getOne(qw.eq(field, value));
    }

    public void deleteById(Integer id){
        inventoryAdjustDetailService.deleteByBillNo(getById(id).getBillNo());
        super.removeById(id);
    }

}
